/*
ID: icerupt1
PROG: msquare
LANG: C++11
*/

/* solution
 *
 *
*/
#include <fstream>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <unordered_set>

std::ifstream fin {"msquare.in" };
std::ofstream fout{"msquare.out"};

using data_type = int;

struct msquare
{
	data_type da;
	std::string path;
};

int const pow10[8] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000};
char const opt[3] = {'A', 'B', 'C'};
int const transform[3][8] = {
								{8, 7, 6, 5, 4, 3, 2, 1},
								{4, 1, 2, 3, 6, 7, 8, 5},
								{1, 7, 2, 4, 5, 3, 6, 8},
							};
std::unordered_set<int> visited;
msquare goal;

void print(std::string s)
{
	for (int i = 0; i < (int)s.size(); i++) {
		if (!(i%60) && i) {
			std::cout << '\n';
			fout << '\n';
		}
		std::cout << s[i];
		fout << s[i];
	}
	std::cout << '\n';
	fout << '\n';
}

auto get_bit(int a, int pos)
{
	a /= pow10[8-pos];
	return a % 10;
}

auto trans(data_type a, int way)
{
	data_type tmp = 0;
	for (int i = 0; i < 8; i++)
		tmp += pow10[7-i] * get_bit(a, transform[way][i]);
	return tmp;
}

int main()
{
	for (int i = 0, x; i < 8; i++) { fin >> x; goal.da = goal.da * 10 + x; }
	if (goal.da == 12345678) {
		std::cout << "0\n\n";
		fout << "0\n\n";
		return 0;
	}
	std::queue<msquare> q;
	q.push({12345678, ""});
	visited.insert(12345678);

	while (!q.empty()) {
		msquare tmp = q.front();
		q.pop();
		for (int i = 0; i < 3; i++) {
			msquare t;
			t.da = trans(tmp.da, i);
			t.path = tmp.path + opt[i];
			if (t.da == goal.da) {
				std::cout << t.path.size() << '\n';
				fout << t.path.size() << '\n';
				print(t.path);
				return 0;
			}
			if (visited.find(t.da) == visited.end()) {
				q.push(t);
				visited.insert(t.da);
			}
		}
	}
}

